<template>
    <div class="dialog">
        <el-dialog title="" :visible.sync="dialogFormVisible">
            <el-form :model="form">
                <el-form-item label="楼盘名称" :label-width="formLabelWidth">
                    <el-input v-model="form.buildName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="所属区域" :label-width="formLabelWidth">
                    <el-input v-model="form.address" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="价格" :label-width="formLabelWidth">
                    <el-input v-model="form.price" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="更新时间" :label-width="formLabelWidth">
                    <el-input v-model="form.time" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="排序" :label-width="formLabelWidth">
                    <el-input v-model="form.sort" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="状态" :label-width="formLabelWidth">
                    <el-input v-model="form.state" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="submin">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
  data () {
    return {
      dialogFormVisible: false,
      form: {
        buildName: '',
        address: '',
        price: '',
        time: '',
        sort: '',
        state: ''
      },
      formLabelWidth: '80px'
    }
  },
  methods: {
    submin () {
      if (this.form.id) {
        this.$api.editHouse(this.form).then(res => {
          console.log(res)
          if (res.data.code === 1) {
            this.form = {
              buildName: '',
              address: '',
              price: '',
              time: '',
              sort: '',
              state: ''
            }
            this.$emit('update')
            this.dialogFormVisible = false
          }
        })
      } else {
        this.$api.addHouse(this.form).then(res => {
          console.log(res)
          if (res.data.code === 1) {
            this.form = {
              buildName: '',
              address: '',
              price: '',
              time: '',
              sort: '',
              state: ''
            }
            this.$emit('update')
            this.dialogFormVisible = false
          }
        })
      }
    }
  }
}
</script>

<style>

</style>
